Object.defineProperty(exports, "__esModule", {
  value: true
});
var LogManager = require("AA_LogManager");
var ArrayUtils = require("AA_ArrayUtils");
var ObjectUtils = require("AA_ObjectUtils");
var PlayerDataManager = require("AA_PlayerDataManager");
var Excel = require("AA_Excel");
var Const_Game = require("AA_Const_Game");
var GameDataManager = require("AA_GameDataManager");
var GameGlobalVariable = require("AA_GameGlobalVariable");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
_decorator.property;
_decorator.inspector;
var _def_Logic_GetEquip = function () {
  function _creator() {
    this.geZiBiChuCount = 5;
    this.oneGeZiId = 1;
    this.getCellListArray = [];
    this.zaZhongMap = new Map();
  }
  var t = _creator;
  Object.defineProperty(_creator, "I", {
    get: function () {
      if (!this._instance) {
        this._instance = new t();
        this._instance.StartCheckData();
        this._instance.StartSetShuiGuoLevel();
      }
      return this._instance;
    },
    enumerable: false,
    configurable: true
  });
  _creator.prototype.GetEquip = function (e, t, o, n) {
    var i = this;
    GameDataManager.GameDataMgr.gameBag.pickCardCount++;
    t && GameDataManager.GameDataMgr.gameBag.videoCount++;
    var s = [];
    this.weight.forEach(function (e, t) {
      if (3 == i.equipPool[t].level || 2 == i.equipPool[t].level) {
        s.push(e + 0);
      } else {
        s.push(e);
      }
    });
    o <= 1 && this.geZiIdArray.forEach(function (e) {
      s[e - 1] = 1 == o && e == i.oneGeZiId ? s[e - 1] : 0;
    });
    GameDataManager.GameDataMgr.gameBag.geZiBaoDi++;
    LogManager.LogMgr.debug("格子保底数量:", GameDataManager.GameDataMgr.gameBag.geZiBaoDi);
    var h = [];
    for (var f = 0; f < e; f++) {
      var g = undefined;
      if (0 == f && t) {
        g = ArrayUtils.default.getWeightRandom(this.videoWeight);
      } else {
        if (-1 != (g = this.GetTeShuData(f))) {
          h.push(ObjectUtils.default.deepCopy(Excel.Excel.bagEquipRule(g)));
          continue;
        }
        if (GameDataManager.GameDataMgr.gameBag.geZiBaoDi >= this.geZiBiChuCount && o > 0) {
          g = 1 == o ? this.oneGeZiId - 1 : this.geZiIdArray[ArrayUtils.default.getWeightRandom(this.geZiWeight)] - 1;
        } else {
          var _ = undefined;
          do {
            g = ArrayUtils.default.getWeightRandom(s);
            _ = this.equipPool[g];
          } while (1 == n && _ && (_.shuiguoId == Const_Game.FruitId.杨桃忍者 || _.shuiguoId == Const_Game.FruitId.柠檬精 || _.shuiguoId == Const_Game.FruitId.辣妹子 || _.shuiguoId == Const_Game.FruitId.招财橙子));
        }
      }
      h.push(ObjectUtils.default.deepCopy(this.equipPool[g]));
      if (-1 == this.equipPool[g].level) {
        GameDataManager.GameDataMgr.gameBag.geZiBaoDi = 0;
        LogManager.LogMgr.debug("触发格子保底:", GameDataManager.GameDataMgr.gameBag.geZiBaoDi);
      }
    }
    2 == GameGlobalVariable.GameGlobalVariable.nowlevel && GameDataManager.GameDataMgr.gameBag.getEquipCount++;
    return h;
  };
  _creator.prototype.GetTeShuData = function (e) {
    if (-1 != GameGlobalVariable.GameGlobalVariable.nowlevel) {
      var t = Excel.Excel.gameShuiGuoRule(GameGlobalVariable.GameGlobalVariable.nowlevel);
      if (t && t.rule && GameDataManager.GameDataMgr.gameBag.getEquipCount < t.rule.length && e < t.rule[GameDataManager.GameDataMgr.gameBag.getEquipCount].length) {
        var o = t.rule[GameDataManager.GameDataMgr.gameBag.getEquipCount][e];
        var n = Excel.Excel.bagEquipRule(o);
        if (PlayerDataManager.PlayerDataMgr.GetEquipIsDressUp(n.shuiguoId)) {
          return o;
        }
      }
    }
    return -1;
  };
  _creator.prototype.GetIsGuDingData = function () {
    if (-1 != GameGlobalVariable.GameGlobalVariable.nowlevel) {
      var e = Excel.Excel.gameShuiGuoRule(GameGlobalVariable.GameGlobalVariable.nowlevel);
      if (e && e.rule && GameDataManager.GameDataMgr.gameBag.getEquipCount < e.rule.length) {
        return true;
      }
    }
    return false;
  };
  _creator.prototype.ResetSetCellList = function () {
    this.getCellListArray = [];
  };
  _creator.prototype.GetOneCell = function (e, t, o) {
    var n = [];
    if (1 == GameGlobalVariable.GameGlobalVariable.nowlevel) {
      var i = [];
      switch (o) {
        case 1:
          i = [2, 3];
          break;
        case 2:
          i = [1];
          break;
        case 3:
          i = [4, 5, 6, 7];
      }
      if (i.length > 0) {
        var a = i[Math.floor(Math.random() * i.length)];
        n.push(ObjectUtils.default.deepCopy(this.equipPool[a - 1]));
        return n;
      }
    }
    for (var r = 0; r < e; r++) {
      a = -1;
      if (t > 0) {
        if (1 == t) {
          a = this.oneGeZiId - 1;
        } else {
          var s = 0;
          var u = 0;
          do {
            s = Math.floor(3 * Math.random()) + 1;
            u++;
          } while (-1 != this.getCellListArray.indexOf(s) && u < 1e3);
          this.getCellListArray.push(s);
          i = [];
          switch (s) {
            case 1:
              i = [2, 3];
              break;
            case 2:
              i = [1];
              break;
            case 3:
              i = [4, 5, 6, 7];
          }
          a = i[Math.floor(Math.random() * i.length)] - 1;
        }
      }
      -1 != a && n.push(ObjectUtils.default.deepCopy(this.equipPool[a]));
    }
    return n;
  };
  _creator.prototype.StartCheckData = function () {
    var e = this;
    if (!this.equipPool) {
      this.equipPool = [];
      this.weight = [];
      this.videoWeight = [];
      this.geZiIdArray = [];
      this.geZiWeight = [];
      Excel.Excel.bagEquipRule_all.forEach(function (t) {
        if (-1 == t.level || -1 != PlayerDataManager.PlayerDataMgr.dressUpArray.indexOf(t.shuiguoId) || -1 == Excel.Excel.shuiguo(t.shuiguoId).isShow && 2 == GameGlobalVariable.GameGlobalVariable.isTeShuLevel()) {
          e.equipPool.push(t);
          e.weight.push(t.weight);
          e.videoWeight.push(t.videoWidget);
          if (-1 == t.level) {
            e.geZiIdArray.push(t.id);
            e.geZiWeight.push(t.weight);
          }
        }
      });
    }
  };
  _creator.prototype.StartSetShuiGuoLevel = function () {
    var e = this;
    if (!this.shuiGuoLevelMap) {
      this.shuiGuoLevelMap = new Map();
      Excel.Excel.shuiguohecheng_all.forEach(function (t) {
        e.shuiGuoLevelMap.has(t.shuiguoId) || e.shuiGuoLevelMap.set(t.shuiguoId, []);
        e.shuiGuoLevelMap.get(t.shuiguoId).push(t);
      });
    }
  };
  _creator.prototype.GetEquipUpData = function (e, t) {
    return this.shuiGuoLevelMap.get(e)[t];
  };
  _creator.prototype.GetMaxLevel = function (e) {
    var t = -1;
    var o = Excel.Excel.shuiguo(e);
    if (0 != o.jinjieShuiGuoId) {
      t = o.id;
    } else {
      var n = Excel.Excel.shuiguo(this.GetZaZhongId(e));
      n && 0 != n.jinjieShuiGuoId && (t = n.id);
    }
    if (-1 != t) {
      var i = Excel.Excel.shuiguo(t);
      var a = PlayerDataManager.PlayerDataMgr.GetEquipDataById(t).level;
      if (i.jinJieLv <= a) {
        return GameGlobalVariable.GameGlobalVariable.zaZhongMaxLevel;
      }
    }
    return GameGlobalVariable.GameGlobalVariable.normalMaxLevel;
  };
  _creator.prototype.ResetThis = function () {
    this.equipPool = null;
    this.StartCheckData();
  };
  _creator.prototype.GetZaZhongId = function (e) {
    var t = this;
    0 == this.zaZhongMap.size && Excel.Excel.shuiguo_all.forEach(function (e) {
      if (0 != e.jinjieShuiGuoId) {
        t.zaZhongMap.set(e.id, e.jinjieShuiGuoId);
        t.zaZhongMap.set(e.jinjieShuiGuoId, e.id);
      }
    });
    if (this.zaZhongMap.has(e)) {
      return this.zaZhongMap.get(e);
    } else {
      return -1;
    }
  };
  _creator.prototype.GetMustGetGeZi = function () {
    var e = null;
    if (2 == GameGlobalVariable.GameGlobalVariable.isTeShuLevel() && GameGlobalVariable.GameGlobalVariable.nowlevel && -1 != GameGlobalVariable.GameGlobalVariable.nowlevel) {
      var t = Excel.Excel.shuiguoguanqia(GameGlobalVariable.GameGlobalVariable.nowlevel).levelboshuid.length;
      var o = GameDataManager.GameDataMgr.getNowLevelBoshuState(GameGlobalVariable.GameGlobalVariable.nowlevel, 2) + 1;
      LogManager.LogMgr.debug("maxBoShu:", t, "boshu:", o);
      if (1 == GameGlobalVariable.GameGlobalVariable.nowlevel && 4 == o && GameGlobalVariable.GameGlobalVariable.isFirstGuide) {
        var n = (i = [2, 3])[Math.floor(Math.random() * i.length)];
        return Excel.Excel.bagEquipRule(n);
      }
      if (1 == GameGlobalVariable.GameGlobalVariable.nowlevel && 1 == GameGlobalVariable.GameGlobalVariable.baggeizihelpopen) {
        var i = undefined;
        n = undefined;
        switch (o) {
          case 3:
          case 4:
          case 5:
          case 6:
          case 8:
            return Excel.Excel.bagEquipRule(this.oneGeZiId);
          case 7:
            n = (i = [2, 3])[Math.floor(Math.random() * i.length)];
            return Excel.Excel.bagEquipRule(n);
          case 10:
            n = (i = [4, 5, 6, 7])[Math.floor(Math.random() * i.length)];
            return Excel.Excel.bagEquipRule(n);
        }
      } else if (2 != GameGlobalVariable.GameGlobalVariable.nowlevel || 1 != o && 10 != o || 1 != GameGlobalVariable.GameGlobalVariable.baggeizihelpopen) {
        if (t <= 10 && (4 == o || 7 == o) || t > 10 && (5 == o || 10 == o)) {
          n = (i = [4, 5, 6, 7])[Math.floor(Math.random() * i.length)];
          e = Excel.Excel.bagEquipRule(n);
        }
      } else {
        i = undefined;
        n = undefined;
        switch (o) {
          case 1:
            n = (i = [2, 3])[Math.floor(Math.random() * i.length)];
            return Excel.Excel.bagEquipRule(n);
          case 10:
            n = (i = [4, 5, 6, 7])[Math.floor(Math.random() * i.length)];
            return Excel.Excel.bagEquipRule(n);
        }
      }
    }
    return e;
  };
  _creator.prototype.GetVideoEquip = function (e) {
    var t = [];
    var o = [];
    PlayerDataManager.PlayerDataMgr.dressUpArray.forEach(function (e) {
      o.push(e);
    });
    for (var n = 0; n < o.length; n++) {
      if (o[n]) {
        switch (o[n]) {
          case Const_Game.FruitId.杨桃忍者:
          case Const_Game.FruitId.柠檬精:
          case Const_Game.FruitId.辣妹子:
          case Const_Game.FruitId.招财橙子:
            o[n] = 0;
        }
      }
    }
    var i = o.filter(function (e) {
      return 0 != e;
    });
    var a = [];
    if (i && 0 != i.length) {
      Excel.Excel.bagEquipRule_all.forEach(function (e) {
        3 == e.level && -1 != i.indexOf(e.shuiguoId) && a.push(e.id);
      });
    } else {
      Excel.Excel.bagEquipRule_all.forEach(function (e) {
        switch (e.shuiguoId) {
          case Const_Game.FruitId.杨桃忍者:
          case Const_Game.FruitId.柠檬精:
          case Const_Game.FruitId.辣妹子:
          case Const_Game.FruitId.招财橙子:
            break;
          default:
            3 == e.level && a.push(e.id);
        }
      });
    }
    for (n = 0; n < e; n++) {
      var r = a[Math.floor(Math.random() * a.length)];
      var d = ObjectUtils.default.deepCopy(Excel.Excel.bagEquipRule(r));
      t.push(d);
    }
    return t;
  };
  _creator.prototype.GetThreeCell = function (e, t) {
    var o = [];
    if (t > 0) {
      var n = [4, 5, 6, 7];
      for (var i = 0; i < e; i++) {
        var a = n[Math.floor(Math.random() * n.length)];
        var r = ObjectUtils.default.deepCopy(Excel.Excel.bagEquipRule(a));
        o.push(r);
      }
    }
    return o;
  };
  return t = __decorate([_ccclass], _creator);
}();
exports.default = _def_Logic_GetEquip;